@trazum/core 1.45.0 → 1.47.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/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts +231 -0
- package/dist/init.d.ts.map +1 -0
- package/dist/init.js +325 -0
- package/dist/init.js.map +1 -0
- package/dist/plan.d.ts +52 -0
- package/dist/plan.d.ts.map +1 -1
- package/dist/plan.js +75 -0
- package/dist/plan.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +15 -1
- package/src/init.ts +500 -0
- package/src/plan.ts +88 -0
package/dist/index.d.ts
CHANGED
|
@@ -13,13 +13,16 @@ export { coverageDrift, COVERAGE_FIELDS, COVERAGE_DRIFT_MIN } from './coverage-d
|
|
|
13
13
|
export { explainGateFailure, gateMargin, GATE_MARGIN_TIGHT } from './gate-explain.js';
|
|
14
14
|
export { measuredUsage, labelCoverage, MIN_SCALE_DAYS, SCALE_TO_DAYS } from './measured-profile.js';
|
|
15
15
|
export { assignSources, fleetRollup } from './fleet.js';
|
|
16
|
-
export { buildPlan, planLabelName } from './plan.js';
|
|
16
|
+
export { buildPlan, planLabelName, parsePlanDocument, PLAN_ACTION_KINDS } from './plan.js';
|
|
17
|
+
export type { PlanParseFailure, PlanParseResult } from './plan.js';
|
|
17
18
|
export type { PlanAction, PlanActionKind, PlanAssumption, PlanDocument } from './plan.js';
|
|
18
19
|
export { verifyPlan } from './verify.js';
|
|
19
20
|
export { buildHistory, storedReportFrom, MIN_RUN } from './history.js';
|
|
20
21
|
export { answerCost } from './answer.js';
|
|
21
22
|
export { guardSpend } from './guard.js';
|
|
22
23
|
export type { GuardAlternative, GuardAnswer, GuardRequest, GuardVerdict } from './guard.js';
|
|
24
|
+
export { proposeInit, HEADLINE_FLOOR_SHARE, MIN_RATE_DAYS } from './init.js';
|
|
25
|
+
export type { InitDecline, InitHeadline, InitJustification, InitKey, InitObservations, InitOptions, InitProposal, NoHeadline, ProviderSighting, UsageSighting, } from './init.js';
|
|
23
26
|
export type { AnswerRequest, AnswerVerdict, BudgetPosition, CallEstimate, CannotTellReasonAnswer, CostAnswer, } from './answer.js';
|
|
24
27
|
export { evaluateWatch, firedKey, COVERAGE_FLOOR, DAY_MS } from './watch.js';
|
|
25
28
|
export type { NotJudgeable, WatchAbstention, WatchCrossing, WatchGate, WatchOptions, WatchResult, WatchThresholds, } from './watch.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,uBAAuB,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAC/F,OAAO,EACL,UAAU,EACV,cAAc,EACd,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,QAAQ,GACT,MAAM,YAAY,CAAC;AACpB,YAAY,EACV,cAAc,EACd,YAAY,EACZ,mBAAmB,EACnB,cAAc,EACd,aAAa,EACb,kBAAkB,EAClB,WAAW,EACX,WAAW,GACZ,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AAGlF,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACtF,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAQ7F,OAAO,EACL,mBAAmB,EACnB,uBAAuB,EACvB,wBAAwB,EACxB,6BAA6B,EAC7B,YAAY,GACb,MAAM,UAAU,CAAC;AAClB,YAAY,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AA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,EACjB,WAAW,EACX,kBAAkB,EAClB,gBAAgB,EAChB,uBAAuB,EACvB,SAAS,EACT,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChG,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -18,11 +18,12 @@ export { coverageDrift, COVERAGE_FIELDS, COVERAGE_DRIFT_MIN } from './coverage-d
|
|
|
18
18
|
export { explainGateFailure, gateMargin, GATE_MARGIN_TIGHT } from './gate-explain.js';
|
|
19
19
|
export { measuredUsage, labelCoverage, MIN_SCALE_DAYS, SCALE_TO_DAYS } from './measured-profile.js';
|
|
20
20
|
export { assignSources, fleetRollup } from './fleet.js';
|
|
21
|
-
export { buildPlan, planLabelName } from './plan.js';
|
|
21
|
+
export { buildPlan, planLabelName, parsePlanDocument, PLAN_ACTION_KINDS } from './plan.js';
|
|
22
22
|
export { verifyPlan } from './verify.js';
|
|
23
23
|
export { buildHistory, storedReportFrom, MIN_RUN } from './history.js';
|
|
24
24
|
export { answerCost } from './answer.js';
|
|
25
25
|
export { guardSpend } from './guard.js';
|
|
26
|
+
export { proposeInit, HEADLINE_FLOOR_SHARE, MIN_RATE_DAYS } from './init.js';
|
|
26
27
|
export { evaluateWatch, firedKey, COVERAGE_FLOOR, DAY_MS } from './watch.js';
|
|
27
28
|
export { STORE_SCHEMA_VERSION, identityOf, resolveStore, recordsFromBuckets, bucketsFromRecords, storeInventory, pruneRecords, } from './store.js';
|
|
28
29
|
export { CONNECTORS, connectorFor, normalizeAnthropicUsage, normalizeOpenAIUsage, bucketedProfile, bucketedCacheEconomics, } from './connector.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CA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,EAAE,MAAM,cAAc,CAAC;AAGpE,qEAAqE;AACrE,OAAO,EAAE,cAAc,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAC;AAG3E,kFAAkF;AAClF,kFAAkF;AAClF,wCAAwC;AACxC,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAGzF,mEAAmE;AACnE,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAGjE,gCAAgC;AAChC,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAQ9C,0EAA0E;AAC1E,+EAA+E;AAC/E,8EAA8E;AAC9E,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEzD,8EAA8E;AAC9E,6EAA6E;AAC7E,2DAA2D;AAC3D,OAAO,EACL,eAAe,EACf,WAAW,EACX,iBAAiB,EACjB,WAAW,EACX,kBAAkB,EAClB,gBAAgB,EAChB,uBAAuB,EACvB,SAAS,EACT,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/init.d.ts
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The first five minutes, decided without touching a disk.
|
|
3
|
+
*
|
|
4
|
+
* Everything since 1.41 raised the ceiling. This lowers the floor: from
|
|
5
|
+
* `npx @trazum/cli` to a finding worth money, without reading a page of
|
|
6
|
+
* documentation. Twenty-one commands is a wall to somebody who has none of
|
|
7
|
+
* them yet, and that wall is why a good tool gets closed inside a minute.
|
|
8
|
+
*
|
|
9
|
+
* **The proposal is a document, not a side effect.** What `init` would write
|
|
10
|
+
* is decided here, from observations the CLI collected, and returned as a
|
|
11
|
+
* value. So every rule below is testable without a filesystem, and `--dry-run`
|
|
12
|
+
* is the same code path minus the write rather than a second implementation
|
|
13
|
+
* that drifts from the first.
|
|
14
|
+
*
|
|
15
|
+
* **A key with no evidence is not written.** A generated config full of
|
|
16
|
+
* guessed thresholds is a config nobody trusts and everybody deletes — and it
|
|
17
|
+
* is worse than an empty one, because it looks like a decision somebody made.
|
|
18
|
+
* Every key that lands carries the observation that justified it; every key
|
|
19
|
+
* that does not carries what would settle it. Both are typed values, because a
|
|
20
|
+
* first run that explains itself only in prose cannot be checked by a test.
|
|
21
|
+
*
|
|
22
|
+
* **Measurement is not policy.** A log says what your traffic *was* — how many
|
|
23
|
+
* calls, which model, how long the outputs ran. Those are measurements and
|
|
24
|
+
* this file writes them. A budget says what your traffic *may cost*, which no
|
|
25
|
+
* log can answer: picking "the measured month plus twenty per cent" would be
|
|
26
|
+
* this tool inventing a threshold and then grading somebody against it. So
|
|
27
|
+
* `spend` is always declined, and the measured figure is handed over so the
|
|
28
|
+
* person who *can* set a budget has the number in front of them.
|
|
29
|
+
*/
|
|
30
|
+
import type { TrazumConfig } from './config-schema.js';
|
|
31
|
+
import type { Detection, EvidenceKind } from './detect.js';
|
|
32
|
+
import type { HostEnvironment } from './host.js';
|
|
33
|
+
import type { SliceLevers } from './levers.js';
|
|
34
|
+
import type { PricingCatalogue } from './pricing.js';
|
|
35
|
+
import type { UsageProfileReport } from './usage.js';
|
|
36
|
+
import type { Locale } from './i18n/index.js';
|
|
37
|
+
/** A source file that was read, and what `detectFromSource` made of it. */
|
|
38
|
+
export interface ProviderSighting {
|
|
39
|
+
file: string;
|
|
40
|
+
detection: Detection;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Something that might hold usage, found lying around.
|
|
44
|
+
*
|
|
45
|
+
* `where` is a path for the file kinds and the **name** of an environment
|
|
46
|
+
* variable for a credential — never its value. That rule has held since the
|
|
47
|
+
* connector shipped in 1.41 and it holds here: a first-run summary is the
|
|
48
|
+
* single most likely thing somebody pastes into a chat window.
|
|
49
|
+
*/
|
|
50
|
+
export interface UsageSighting {
|
|
51
|
+
kind: 'log-file' | 'log-directory' | 'store' | 'connector-credential';
|
|
52
|
+
where: string;
|
|
53
|
+
/** The provider this source belongs to, when the sighting names one. */
|
|
54
|
+
provider: string | null;
|
|
55
|
+
}
|
|
56
|
+
/** Everything the CLI saw, handed over as data. */
|
|
57
|
+
export interface InitObservations {
|
|
58
|
+
host: HostEnvironment;
|
|
59
|
+
/** Every source file read, strongest evidence first within each file. */
|
|
60
|
+
sightings: ProviderSighting[];
|
|
61
|
+
/** Prompt files the walk found. */
|
|
62
|
+
promptFiles: string[];
|
|
63
|
+
/** Usage sources found. Empty is a real answer and is reported as one. */
|
|
64
|
+
usage: UsageSighting[];
|
|
65
|
+
/**
|
|
66
|
+
* The profile of a usage source that was found **and** parsed.
|
|
67
|
+
*
|
|
68
|
+
* Null covers two different situations and the proposal keeps them apart:
|
|
69
|
+
* nothing was found, or something was found and could not be read. The
|
|
70
|
+
* caller says which by what it puts in `usage`.
|
|
71
|
+
*/
|
|
72
|
+
measured: UsageProfileReport | null;
|
|
73
|
+
/** The locale the environment asked for, when it asked for one. */
|
|
74
|
+
locale: Locale | null;
|
|
75
|
+
/** A config already sitting in the working directory. */
|
|
76
|
+
existing: {
|
|
77
|
+
path: string;
|
|
78
|
+
config: TrazumConfig;
|
|
79
|
+
} | null;
|
|
80
|
+
}
|
|
81
|
+
/** Every config key `init` is allowed to have an opinion about. */
|
|
82
|
+
export type InitKey = 'locale' | 'extensions' | 'usage.model' | 'usage.callsPerMonth' | 'usage.avgOutputTokens' | 'usage.cacheHitRate' | 'usage.batchEligible' | 'labels' | 'spend.maxUsd';
|
|
83
|
+
/** Why a key was written, in a shape a test can assert on. */
|
|
84
|
+
export type InitJustification = {
|
|
85
|
+
key: 'locale';
|
|
86
|
+
value: Locale;
|
|
87
|
+
from: 'environment';
|
|
88
|
+
} | {
|
|
89
|
+
key: 'extensions';
|
|
90
|
+
value: string[];
|
|
91
|
+
from: 'walk';
|
|
92
|
+
files: number;
|
|
93
|
+
} | {
|
|
94
|
+
key: 'usage.model';
|
|
95
|
+
value: string;
|
|
96
|
+
from: 'measured';
|
|
97
|
+
/** Share of the measured bill this model carries, 0-1. */
|
|
98
|
+
share: number;
|
|
99
|
+
} | {
|
|
100
|
+
key: 'usage.model';
|
|
101
|
+
value: string;
|
|
102
|
+
from: 'source';
|
|
103
|
+
file: string;
|
|
104
|
+
line: number;
|
|
105
|
+
evidence: EvidenceKind;
|
|
106
|
+
} | {
|
|
107
|
+
key: 'usage.callsPerMonth';
|
|
108
|
+
value: number;
|
|
109
|
+
from: 'measured';
|
|
110
|
+
calls: number;
|
|
111
|
+
days: number;
|
|
112
|
+
} | {
|
|
113
|
+
key: 'usage.avgOutputTokens';
|
|
114
|
+
value: number;
|
|
115
|
+
from: 'measured';
|
|
116
|
+
outputTokens: number;
|
|
117
|
+
calls: number;
|
|
118
|
+
} | {
|
|
119
|
+
key: 'usage.cacheHitRate';
|
|
120
|
+
value: number;
|
|
121
|
+
from: 'measured';
|
|
122
|
+
cacheReadTokens: number;
|
|
123
|
+
inputTokens: number;
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* Why a key was left out, and what would settle it.
|
|
127
|
+
*
|
|
128
|
+
* A refusal never arrives bare — the rule the guard established in 1.45, here
|
|
129
|
+
* applied to a file rather than to a call. "No provider written" with nothing
|
|
130
|
+
* after it is indistinguishable from a bug.
|
|
131
|
+
*/
|
|
132
|
+
export type InitDecline = {
|
|
133
|
+
key: 'usage.model';
|
|
134
|
+
why: 'no-evidence';
|
|
135
|
+
} | {
|
|
136
|
+
key: 'usage.model';
|
|
137
|
+
why: 'conflicting-evidence';
|
|
138
|
+
files: string[];
|
|
139
|
+
} | {
|
|
140
|
+
key: 'usage.model';
|
|
141
|
+
why: 'provider-only';
|
|
142
|
+
provider: string;
|
|
143
|
+
file: string;
|
|
144
|
+
} | {
|
|
145
|
+
key: 'usage.callsPerMonth';
|
|
146
|
+
why: 'nothing-measured';
|
|
147
|
+
} | {
|
|
148
|
+
key: 'usage.callsPerMonth';
|
|
149
|
+
why: 'window-too-short';
|
|
150
|
+
days: number;
|
|
151
|
+
calls: number;
|
|
152
|
+
} | {
|
|
153
|
+
key: 'usage.callsPerMonth';
|
|
154
|
+
why: 'undated-calls';
|
|
155
|
+
undated: number;
|
|
156
|
+
calls: number;
|
|
157
|
+
} | {
|
|
158
|
+
key: 'usage.avgOutputTokens';
|
|
159
|
+
why: 'nothing-measured';
|
|
160
|
+
} | {
|
|
161
|
+
key: 'usage.cacheHitRate';
|
|
162
|
+
why: 'nothing-measured';
|
|
163
|
+
} | {
|
|
164
|
+
key: 'usage.cacheHitRate';
|
|
165
|
+
why: 'not-recorded';
|
|
166
|
+
} | {
|
|
167
|
+
key: 'usage.batchEligible';
|
|
168
|
+
why: 'only-you-know';
|
|
169
|
+
} | {
|
|
170
|
+
key: 'labels';
|
|
171
|
+
why: 'unprovable';
|
|
172
|
+
labels: number;
|
|
173
|
+
} | {
|
|
174
|
+
key: 'spend.maxUsd';
|
|
175
|
+
why: 'a-budget-is-a-policy';
|
|
176
|
+
measuredUsd: number | null;
|
|
177
|
+
days: number | null;
|
|
178
|
+
};
|
|
179
|
+
/**
|
|
180
|
+
* The single most valuable thing the first run found, with its arithmetic.
|
|
181
|
+
*
|
|
182
|
+
* One finding, not a ranked table. `doctor` and `plan` exist for the table,
|
|
183
|
+
* and a first run that opens with fourteen rows has told somebody nothing —
|
|
184
|
+
* they came to find out whether this is worth an afternoon.
|
|
185
|
+
*/
|
|
186
|
+
export interface InitHeadline {
|
|
187
|
+
slice: SliceLevers;
|
|
188
|
+
/** Which lever the figure is. `route+batch` is computed, never summed. */
|
|
189
|
+
lever: 'route' | 'batch' | 'route+batch';
|
|
190
|
+
savingUsd: number;
|
|
191
|
+
/** Always measured. Nothing in a headline rests on a call that never happened. */
|
|
192
|
+
provenance: 'measured';
|
|
193
|
+
/** Days of measurement behind it, so the figure has a unit a reader can check. */
|
|
194
|
+
days: number;
|
|
195
|
+
}
|
|
196
|
+
export type NoHeadline = 'nothing-measured' | 'nothing-could-be-priced' | 'no-lever-clears-the-floor';
|
|
197
|
+
export interface InitProposal {
|
|
198
|
+
schemaVersion: 1;
|
|
199
|
+
/** Exactly the keys that were justified, and nothing else. */
|
|
200
|
+
config: TrazumConfig;
|
|
201
|
+
justified: InitJustification[];
|
|
202
|
+
declined: InitDecline[];
|
|
203
|
+
headline: InitHeadline | null;
|
|
204
|
+
/** Set when `headline` is null, so "nothing found" is never bare. */
|
|
205
|
+
noHeadline: NoHeadline | null;
|
|
206
|
+
/**
|
|
207
|
+
* The config already there, and which of its keys this proposal would
|
|
208
|
+
* change. Named before anything is written: an `init` that silently replaces
|
|
209
|
+
* a config somebody tuned is the worst possible first impression.
|
|
210
|
+
*/
|
|
211
|
+
overwrites: {
|
|
212
|
+
path: string;
|
|
213
|
+
keys: InitKey[];
|
|
214
|
+
} | null;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* The shortest measured span that may be stated as a monthly rate.
|
|
218
|
+
*
|
|
219
|
+
* Four weeks, so every weekday appears the same number of times. Three days of
|
|
220
|
+
* traffic multiplied by ten is a forecast wearing a measurement's clothes, and
|
|
221
|
+
* this repository has refused that since the series shipped in 1.40.
|
|
222
|
+
*/
|
|
223
|
+
export declare const MIN_RATE_DAYS = 28;
|
|
224
|
+
/** The share of the bill a headline must clear to be worth being the headline. */
|
|
225
|
+
export declare const HEADLINE_FLOOR_SHARE = 0.01;
|
|
226
|
+
export interface InitOptions {
|
|
227
|
+
catalogue: PricingCatalogue;
|
|
228
|
+
on?: Date;
|
|
229
|
+
}
|
|
230
|
+
export declare function proposeInit(observations: InitObservations, options: InitOptions): InitProposal;
|
|
231
|
+
//# sourceMappingURL=init.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AAAA;;;;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
+
*
|
|
4
|
+
* Everything since 1.41 raised the ceiling. This lowers the floor: from
|
|
5
|
+
* `npx @trazum/cli` to a finding worth money, without reading a page of
|
|
6
|
+
* documentation. Twenty-one commands is a wall to somebody who has none of
|
|
7
|
+
* them yet, and that wall is why a good tool gets closed inside a minute.
|
|
8
|
+
*
|
|
9
|
+
* **The proposal is a document, not a side effect.** What `init` would write
|
|
10
|
+
* is decided here, from observations the CLI collected, and returned as a
|
|
11
|
+
* value. So every rule below is testable without a filesystem, and `--dry-run`
|
|
12
|
+
* is the same code path minus the write rather than a second implementation
|
|
13
|
+
* that drifts from the first.
|
|
14
|
+
*
|
|
15
|
+
* **A key with no evidence is not written.** A generated config full of
|
|
16
|
+
* guessed thresholds is a config nobody trusts and everybody deletes — and it
|
|
17
|
+
* is worse than an empty one, because it looks like a decision somebody made.
|
|
18
|
+
* Every key that lands carries the observation that justified it; every key
|
|
19
|
+
* that does not carries what would settle it. Both are typed values, because a
|
|
20
|
+
* first run that explains itself only in prose cannot be checked by a test.
|
|
21
|
+
*
|
|
22
|
+
* **Measurement is not policy.** A log says what your traffic *was* — how many
|
|
23
|
+
* calls, which model, how long the outputs ran. Those are measurements and
|
|
24
|
+
* this file writes them. A budget says what your traffic *may cost*, which no
|
|
25
|
+
* log can answer: picking "the measured month plus twenty per cent" would be
|
|
26
|
+
* this tool inventing a threshold and then grading somebody against it. So
|
|
27
|
+
* `spend` is always declined, and the measured figure is handed over so the
|
|
28
|
+
* person who *can* set a budget has the number in front of them.
|
|
29
|
+
*/
|
|
30
|
+
import { DEFAULT_EXTENSIONS } from './config-schema.js';
|
|
31
|
+
import { billLevers } from './levers.js';
|
|
32
|
+
/** A month, for turning a measured span into a rate. */
|
|
33
|
+
const DAYS_PER_MONTH = 30;
|
|
34
|
+
/**
|
|
35
|
+
* The shortest measured span that may be stated as a monthly rate.
|
|
36
|
+
*
|
|
37
|
+
* Four weeks, so every weekday appears the same number of times. Three days of
|
|
38
|
+
* traffic multiplied by ten is a forecast wearing a measurement's clothes, and
|
|
39
|
+
* this repository has refused that since the series shipped in 1.40.
|
|
40
|
+
*/
|
|
41
|
+
export const MIN_RATE_DAYS = 28;
|
|
42
|
+
/** The share of the bill a headline must clear to be worth being the headline. */
|
|
43
|
+
export const HEADLINE_FLOOR_SHARE = 0.01;
|
|
44
|
+
/** Days between two `YYYY-MM-DD` days, inclusive of both. */
|
|
45
|
+
function spanDays(first, last) {
|
|
46
|
+
const a = Date.parse(`${first}T00:00:00Z`);
|
|
47
|
+
const b = Date.parse(`${last}T00:00:00Z`);
|
|
48
|
+
if (Number.isNaN(a) || Number.isNaN(b))
|
|
49
|
+
return 0;
|
|
50
|
+
return Math.round((b - a) / 86_400_000) + 1;
|
|
51
|
+
}
|
|
52
|
+
/** The extensions actually present among the prompt files found. */
|
|
53
|
+
function extensionsOf(files) {
|
|
54
|
+
const seen = new Set();
|
|
55
|
+
for (const file of files) {
|
|
56
|
+
const dot = file.lastIndexOf('.');
|
|
57
|
+
const slash = Math.max(file.lastIndexOf('/'), file.lastIndexOf('\\'));
|
|
58
|
+
if (dot > slash + 1)
|
|
59
|
+
seen.add(file.slice(dot).toLowerCase());
|
|
60
|
+
}
|
|
61
|
+
return [...seen].sort();
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The one model a config may name, from what was measured.
|
|
65
|
+
*
|
|
66
|
+
* A log spread across four models has no single answer, and writing the
|
|
67
|
+
* largest of the four would silently price every prompt in the repository
|
|
68
|
+
* against a model most of them never touch. The threshold is a majority: past
|
|
69
|
+
* half the bill, "this is what you use" is a fair sentence.
|
|
70
|
+
*/
|
|
71
|
+
function dominantModel(report) {
|
|
72
|
+
if (report.total.totalUsd <= 0 || report.byModel.length === 0)
|
|
73
|
+
return null;
|
|
74
|
+
const top = report.byModel[0];
|
|
75
|
+
if (top === undefined)
|
|
76
|
+
return null;
|
|
77
|
+
const share = top.breakdown.totalUsd / report.total.totalUsd;
|
|
78
|
+
return share > 0.5 ? { model: top.model, share } : null;
|
|
79
|
+
}
|
|
80
|
+
export function proposeInit(observations, options) {
|
|
81
|
+
const { catalogue, on = new Date() } = options;
|
|
82
|
+
const { measured } = observations;
|
|
83
|
+
const justified = [];
|
|
84
|
+
const declined = [];
|
|
85
|
+
const config = {};
|
|
86
|
+
// --- locale -------------------------------------------------------------
|
|
87
|
+
if (observations.locale !== null) {
|
|
88
|
+
config.locale = observations.locale;
|
|
89
|
+
justified.push({ key: 'locale', value: observations.locale, from: 'environment' });
|
|
90
|
+
}
|
|
91
|
+
// --- extensions ---------------------------------------------------------
|
|
92
|
+
//
|
|
93
|
+
// Only when the walk found something the defaults do not already cover.
|
|
94
|
+
// Writing `[".txt", ".md", ".prompt", ".tmpl"]` back into a config is a key
|
|
95
|
+
// that changes nothing and has to be maintained forever.
|
|
96
|
+
const extensions = extensionsOf(observations.promptFiles);
|
|
97
|
+
if (extensions.length > 0 && extensions.some((e) => !DEFAULT_EXTENSIONS.includes(e))) {
|
|
98
|
+
config.extensions = extensions;
|
|
99
|
+
justified.push({
|
|
100
|
+
key: 'extensions',
|
|
101
|
+
value: extensions,
|
|
102
|
+
from: 'walk',
|
|
103
|
+
files: observations.promptFiles.length,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
// --- usage.model --------------------------------------------------------
|
|
107
|
+
//
|
|
108
|
+
// Measured beats detected, and it is not close. An import says which SDK
|
|
109
|
+
// somebody installed; a log says which model was billed. When there is no
|
|
110
|
+
// log, a literal in the source will do — but a *provider* with no model is
|
|
111
|
+
// declined rather than filled in from that provider's default. `where` may
|
|
112
|
+
// print a provider default because a reader can see it is a guess; a config
|
|
113
|
+
// file cannot, because six weeks later it reads as a decision.
|
|
114
|
+
const dominant = measured === null ? null : dominantModel(measured);
|
|
115
|
+
const modelSighting = observations.sightings.find((s) => s.detection.model !== null && s.detection.conflicts.length === 0);
|
|
116
|
+
const conflicting = observations.sightings.filter((s) => s.detection.conflicts.length > 0);
|
|
117
|
+
const providerOnly = observations.sightings.find((s) => s.detection.provider !== null && s.detection.model === null && s.detection.conflicts.length === 0);
|
|
118
|
+
if (dominant !== null) {
|
|
119
|
+
config.usage = { ...config.usage, model: dominant.model };
|
|
120
|
+
justified.push({
|
|
121
|
+
key: 'usage.model',
|
|
122
|
+
value: dominant.model,
|
|
123
|
+
from: 'measured',
|
|
124
|
+
share: dominant.share,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
else if (modelSighting !== undefined) {
|
|
128
|
+
const evidence = modelSighting.detection.evidence.find((e) => e.model !== undefined) ??
|
|
129
|
+
modelSighting.detection.evidence[0];
|
|
130
|
+
config.usage = { ...config.usage, model: modelSighting.detection.model };
|
|
131
|
+
justified.push({
|
|
132
|
+
key: 'usage.model',
|
|
133
|
+
value: modelSighting.detection.model,
|
|
134
|
+
from: 'source',
|
|
135
|
+
file: modelSighting.file,
|
|
136
|
+
line: evidence?.line ?? 0,
|
|
137
|
+
evidence: evidence?.kind ?? 'model-literal',
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
else if (conflicting.length > 0) {
|
|
141
|
+
declined.push({
|
|
142
|
+
key: 'usage.model',
|
|
143
|
+
why: 'conflicting-evidence',
|
|
144
|
+
files: conflicting.map((s) => s.file),
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
else if (providerOnly !== undefined) {
|
|
148
|
+
declined.push({
|
|
149
|
+
key: 'usage.model',
|
|
150
|
+
why: 'provider-only',
|
|
151
|
+
provider: providerOnly.detection.provider,
|
|
152
|
+
file: providerOnly.file,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
declined.push({ key: 'usage.model', why: 'no-evidence' });
|
|
157
|
+
}
|
|
158
|
+
// --- the measured span, which three keys below depend on ----------------
|
|
159
|
+
const dated = measured?.spendByDay ?? [];
|
|
160
|
+
const first = dated[0];
|
|
161
|
+
const last = dated[dated.length - 1];
|
|
162
|
+
const days = first === undefined || last === undefined ? 0 : spanDays(first.day, last.day);
|
|
163
|
+
const datedCalls = dated.reduce((sum, d) => sum + d.calls, 0);
|
|
164
|
+
const undated = measured === null ? 0 : Math.max(0, measured.total.calls - datedCalls);
|
|
165
|
+
// --- usage.callsPerMonth ------------------------------------------------
|
|
166
|
+
//
|
|
167
|
+
// Three separate refusals, and they are not the same refusal. No log is one
|
|
168
|
+
// situation; a log covering four days is another; a log whose records carry
|
|
169
|
+
// no clock is a third — and that last one is the one that would go wrong
|
|
170
|
+
// quietly, because the calls are all *there*, they simply cannot be placed
|
|
171
|
+
// in time. Dividing them by a span they were never proven to fall inside is
|
|
172
|
+
// how a rate comes out too high and nobody can see why.
|
|
173
|
+
if (measured === null) {
|
|
174
|
+
declined.push({ key: 'usage.callsPerMonth', why: 'nothing-measured' });
|
|
175
|
+
}
|
|
176
|
+
else if (undated > 0) {
|
|
177
|
+
declined.push({
|
|
178
|
+
key: 'usage.callsPerMonth',
|
|
179
|
+
why: 'undated-calls',
|
|
180
|
+
undated,
|
|
181
|
+
calls: measured.total.calls,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
else if (days < MIN_RATE_DAYS) {
|
|
185
|
+
declined.push({
|
|
186
|
+
key: 'usage.callsPerMonth',
|
|
187
|
+
why: 'window-too-short',
|
|
188
|
+
days,
|
|
189
|
+
calls: measured.total.calls,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
const perMonth = Math.round((measured.total.calls / days) * DAYS_PER_MONTH);
|
|
194
|
+
config.usage = { ...config.usage, callsPerMonth: perMonth };
|
|
195
|
+
justified.push({
|
|
196
|
+
key: 'usage.callsPerMonth',
|
|
197
|
+
value: perMonth,
|
|
198
|
+
from: 'measured',
|
|
199
|
+
calls: measured.total.calls,
|
|
200
|
+
days,
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
// --- usage.avgOutputTokens ----------------------------------------------
|
|
204
|
+
//
|
|
205
|
+
// An average of what happened, not a forecast of what will — so unlike the
|
|
206
|
+
// rate above it needs no minimum span. One day of real calls gives a real
|
|
207
|
+
// average of those calls.
|
|
208
|
+
if (measured === null || measured.total.calls === 0) {
|
|
209
|
+
declined.push({ key: 'usage.avgOutputTokens', why: 'nothing-measured' });
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
const avg = Math.round(measured.total.outputTokens / measured.total.calls);
|
|
213
|
+
config.usage = { ...config.usage, avgOutputTokens: avg };
|
|
214
|
+
justified.push({
|
|
215
|
+
key: 'usage.avgOutputTokens',
|
|
216
|
+
value: avg,
|
|
217
|
+
from: 'measured',
|
|
218
|
+
outputTokens: measured.total.outputTokens,
|
|
219
|
+
calls: measured.total.calls,
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
// --- usage.cacheHitRate -------------------------------------------------
|
|
223
|
+
//
|
|
224
|
+
// **Not recorded is not not-happened.** A log with no cache fields at all
|
|
225
|
+
// does not prove a hit rate of zero — it proves the exporter did not write
|
|
226
|
+
// the column. Writing 0 there would tell every later caching advisory that
|
|
227
|
+
// caching is doing nothing, which is a finding invented out of a missing
|
|
228
|
+
// field.
|
|
229
|
+
if (measured === null) {
|
|
230
|
+
declined.push({ key: 'usage.cacheHitRate', why: 'nothing-measured' });
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
const read = measured.total.cacheReadTokens;
|
|
234
|
+
const written = measured.total.cacheWriteTokens;
|
|
235
|
+
const input = measured.total.inputTokens;
|
|
236
|
+
if (read === 0 && written === 0) {
|
|
237
|
+
declined.push({ key: 'usage.cacheHitRate', why: 'not-recorded' });
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
const denominator = read + input;
|
|
241
|
+
const rate = denominator === 0 ? 0 : Math.round((read / denominator) * 100) / 100;
|
|
242
|
+
config.usage = { ...config.usage, cacheHitRate: rate };
|
|
243
|
+
justified.push({
|
|
244
|
+
key: 'usage.cacheHitRate',
|
|
245
|
+
value: rate,
|
|
246
|
+
from: 'measured',
|
|
247
|
+
cacheReadTokens: read,
|
|
248
|
+
inputTokens: input,
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
// --- usage.batchEligible ------------------------------------------------
|
|
253
|
+
//
|
|
254
|
+
// Never written, in either direction. Whether the work tolerates a batch
|
|
255
|
+
// window is a fact about a product decision, and no log records it. A
|
|
256
|
+
// default of `false` would quietly delete the batch lever from every report
|
|
257
|
+
// this config touches; `true` would offer a saving on latency somebody never
|
|
258
|
+
// agreed to give up.
|
|
259
|
+
declined.push({ key: 'usage.batchEligible', why: 'only-you-know' });
|
|
260
|
+
// --- labels -------------------------------------------------------------
|
|
261
|
+
//
|
|
262
|
+
// Mapping a log label to a prompt file is a claim about which file produced
|
|
263
|
+
// which calls, and a directory walk cannot prove one. A wrong entry here is
|
|
264
|
+
// worse than a missing one: `profile` would go and read the wrong file and
|
|
265
|
+
// explain a cache verdict with the wrong prompt's structure, confidently.
|
|
266
|
+
const labels = measured?.byLabel.length ?? 0;
|
|
267
|
+
if (labels > 0)
|
|
268
|
+
declined.push({ key: 'labels', why: 'unprovable', labels });
|
|
269
|
+
// --- spend --------------------------------------------------------------
|
|
270
|
+
//
|
|
271
|
+
// The measured figure is handed over, and the threshold is not invented.
|
|
272
|
+
declined.push({
|
|
273
|
+
key: 'spend.maxUsd',
|
|
274
|
+
why: 'a-budget-is-a-policy',
|
|
275
|
+
measuredUsd: measured === null ? null : measured.total.totalUsd,
|
|
276
|
+
days: measured === null ? null : days,
|
|
277
|
+
});
|
|
278
|
+
// --- the headline -------------------------------------------------------
|
|
279
|
+
let headline = null;
|
|
280
|
+
let noHeadline = null;
|
|
281
|
+
if (measured === null) {
|
|
282
|
+
noHeadline = 'nothing-measured';
|
|
283
|
+
}
|
|
284
|
+
else if (measured.total.totalUsd <= 0) {
|
|
285
|
+
noHeadline = 'nothing-could-be-priced';
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
const levers = billLevers(measured, { catalogue, on, minShare: HEADLINE_FLOOR_SHARE });
|
|
289
|
+
const top = levers.slices[0];
|
|
290
|
+
if (top === undefined || top.combinedUsd <= 0) {
|
|
291
|
+
noHeadline = 'no-lever-clears-the-floor';
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
headline = {
|
|
295
|
+
slice: top,
|
|
296
|
+
lever: top.route !== null && top.batch !== null
|
|
297
|
+
? 'route+batch'
|
|
298
|
+
: top.route !== null
|
|
299
|
+
? 'route'
|
|
300
|
+
: 'batch',
|
|
301
|
+
savingUsd: top.combinedUsd,
|
|
302
|
+
provenance: 'measured',
|
|
303
|
+
days,
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
// --- what this would overwrite ------------------------------------------
|
|
308
|
+
let overwrites = null;
|
|
309
|
+
if (observations.existing !== null) {
|
|
310
|
+
const already = observations.existing.config;
|
|
311
|
+
const keys = [];
|
|
312
|
+
if (config.locale !== undefined && already.locale !== undefined)
|
|
313
|
+
keys.push('locale');
|
|
314
|
+
if (config.extensions !== undefined && already.extensions !== undefined)
|
|
315
|
+
keys.push('extensions');
|
|
316
|
+
for (const k of ['model', 'callsPerMonth', 'avgOutputTokens', 'cacheHitRate']) {
|
|
317
|
+
if (config.usage?.[k] !== undefined && already.usage?.[k] !== undefined) {
|
|
318
|
+
keys.push(`usage.${k}`);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
overwrites = { path: observations.existing.path, keys };
|
|
322
|
+
}
|
|
323
|
+
return { schemaVersion: 1, config, justified, declined, headline, noHeadline, overwrites };
|
|
324
|
+
}
|
|
325
|
+
//# sourceMappingURL=init.js.map
|