agent-nuvira 3.5.2 → 3.5.6
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 +66 -0
- package/dist/cli/chat.d.ts.map +1 -1
- package/dist/cli/chat.js +72 -19
- package/dist/cli/chat.js.map +1 -1
- package/dist/cli/config.d.ts.map +1 -1
- package/dist/cli/config.js +17 -3
- package/dist/cli/config.js.map +1 -1
- package/dist/cli/execute.d.ts.map +1 -1
- package/dist/cli/execute.js +63 -22
- package/dist/cli/execute.js.map +1 -1
- package/dist/cli/failover-runner.js +4 -4
- package/dist/cli/failover-runner.js.map +1 -1
- package/dist/cli/gateway.js +13 -13
- package/dist/cli/gateway.js.map +1 -1
- package/dist/cli/loop-executor.d.ts +22 -0
- package/dist/cli/loop-executor.d.ts.map +1 -1
- package/dist/cli/loop-executor.js +56 -12
- package/dist/cli/loop-executor.js.map +1 -1
- package/dist/cli/stats.d.ts +62 -4
- package/dist/cli/stats.d.ts.map +1 -1
- package/dist/cli/stats.js +282 -5
- package/dist/cli/stats.js.map +1 -1
- package/dist/cli/ui/index.d.ts +2 -2
- package/dist/cli/ui/index.d.ts.map +1 -1
- package/dist/cli/ui/index.js +1 -1
- package/dist/cli/ui/index.js.map +1 -1
- package/dist/cli/ui/presenter.d.ts +43 -0
- package/dist/cli/ui/presenter.d.ts.map +1 -1
- package/dist/cli/ui/presenter.js +88 -1
- package/dist/cli/ui/presenter.js.map +1 -1
- package/dist/config/manager.d.ts +29 -1
- package/dist/config/manager.d.ts.map +1 -1
- package/dist/config/manager.js +178 -143
- package/dist/config/manager.js.map +1 -1
- package/dist/config/paths.d.ts +48 -1
- package/dist/config/paths.d.ts.map +1 -1
- package/dist/config/paths.js +59 -9
- package/dist/config/paths.js.map +1 -1
- package/dist/config/service-catalog.js +1 -1
- package/dist/config/service-catalog.js.map +1 -1
- package/dist/config/service-probe.js +1 -1
- package/dist/config/service-probe.js.map +1 -1
- package/dist/config/types.d.ts +22 -0
- package/dist/config/types.d.ts.map +1 -1
- package/dist/gateway/adapters.js +8 -8
- package/dist/gateway/adapters.js.map +1 -1
- package/dist/gateway/registry.js +1 -1
- package/dist/gateway/registry.js.map +1 -1
- package/dist/learning/auto-router.d.ts +30 -4
- package/dist/learning/auto-router.d.ts.map +1 -1
- package/dist/learning/auto-router.js +54 -38
- package/dist/learning/auto-router.js.map +1 -1
- package/dist/learning/cost-classification.d.ts +188 -0
- package/dist/learning/cost-classification.d.ts.map +1 -0
- package/dist/learning/cost-classification.js +294 -0
- package/dist/learning/cost-classification.js.map +1 -0
- package/dist/learning/cost-ledger-maintenance.d.ts +122 -0
- package/dist/learning/cost-ledger-maintenance.d.ts.map +1 -0
- package/dist/learning/cost-ledger-maintenance.js +289 -0
- package/dist/learning/cost-ledger-maintenance.js.map +1 -0
- package/dist/learning/cost-reconcile.d.ts +160 -0
- package/dist/learning/cost-reconcile.d.ts.map +1 -0
- package/dist/learning/cost-reconcile.js +238 -0
- package/dist/learning/cost-reconcile.js.map +1 -0
- package/dist/learning/cost-tracker.d.ts +134 -13
- package/dist/learning/cost-tracker.d.ts.map +1 -1
- package/dist/learning/cost-tracker.js +190 -68
- package/dist/learning/cost-tracker.js.map +1 -1
- package/dist/learning/model-pricing.d.ts +240 -0
- package/dist/learning/model-pricing.d.ts.map +1 -0
- package/dist/learning/model-pricing.js +309 -0
- package/dist/learning/model-pricing.js.map +1 -0
- package/dist/learning/model-selection.d.ts +15 -0
- package/dist/learning/model-selection.d.ts.map +1 -1
- package/dist/learning/model-selection.js +22 -2
- package/dist/learning/model-selection.js.map +1 -1
- package/dist/learning/model-warmup.d.ts.map +1 -1
- package/dist/learning/model-warmup.js +4 -1
- package/dist/learning/model-warmup.js.map +1 -1
- package/dist/learning/session-store.d.ts +1 -5
- package/dist/learning/session-store.d.ts.map +1 -1
- package/dist/learning/session-store.js +10 -1
- package/dist/learning/session-store.js.map +1 -1
- package/dist/learning/step-checkpoint.d.ts +32 -3
- package/dist/learning/step-checkpoint.d.ts.map +1 -1
- package/dist/learning/step-checkpoint.js +33 -4
- package/dist/learning/step-checkpoint.js.map +1 -1
- package/dist/mcp/settings.d.ts +15 -3
- package/dist/mcp/settings.d.ts.map +1 -1
- package/dist/mcp/settings.js +30 -15
- package/dist/mcp/settings.js.map +1 -1
- package/dist/parity/drivers.d.ts.map +1 -1
- package/dist/parity/drivers.js +31 -5
- package/dist/parity/drivers.js.map +1 -1
- package/dist/tools/child-agent-runtime.d.ts.map +1 -1
- package/dist/tools/child-agent-runtime.js +13 -7
- package/dist/tools/child-agent-runtime.js.map +1 -1
- package/dist/tools/followup-utils.d.ts +36 -0
- package/dist/tools/followup-utils.d.ts.map +1 -1
- package/dist/tools/followup-utils.js +66 -0
- package/dist/tools/followup-utils.js.map +1 -1
- package/dist/tools/modality/browser.js +2 -2
- package/dist/tools/modality/browser.js.map +1 -1
- package/dist/tools/modality/image-gen.d.ts +1 -1
- package/dist/tools/modality/image-gen.js +1 -1
- package/dist/tools/modality/image-providers.js +1 -1
- package/dist/tools/modality/image-providers.js.map +1 -1
- package/dist/tools/modality/vision.d.ts +1 -1
- package/dist/tools/modality/vision.js +1 -1
- package/dist/tools/modality/voice.js +2 -2
- package/dist/tools/modality/voice.js.map +1 -1
- package/dist/tools/neutts-synth.d.ts +3 -3
- package/dist/tools/neutts-synth.js +3 -3
- package/dist/tools/neutts-synth.js.map +1 -1
- package/dist/tools/process-liveness.d.ts +50 -0
- package/dist/tools/process-liveness.d.ts.map +1 -1
- package/dist/tools/process-liveness.js +82 -9
- package/dist/tools/process-liveness.js.map +1 -1
- package/dist/tools/registry.d.ts +1 -1
- package/dist/tools/registry.d.ts.map +1 -1
- package/dist/tools/registry.js +27 -4
- package/dist/tools/registry.js.map +1 -1
- package/dist/tools/run-registry.d.ts.map +1 -1
- package/dist/tools/run-registry.js +14 -1
- package/dist/tools/run-registry.js.map +1 -1
- package/dist/tools/run-terminal.d.ts.map +1 -1
- package/dist/tools/run-terminal.js +18 -1
- package/dist/tools/run-terminal.js.map +1 -1
- package/dist/tools/tool-loop.d.ts.map +1 -1
- package/dist/tools/tool-loop.js +5 -3
- package/dist/tools/tool-loop.js.map +1 -1
- package/dist/tools/web-research.d.ts +1 -1
- package/dist/tools/web-research.js +3 -3
- package/dist/tools/web-research.js.map +1 -1
- package/dist/web-dashboard/chat-console.d.ts +56 -0
- package/dist/web-dashboard/chat-console.d.ts.map +1 -1
- package/dist/web-dashboard/chat-console.js +57 -1
- package/dist/web-dashboard/chat-console.js.map +1 -1
- package/dist/web-dashboard/server.d.ts.map +1 -1
- package/dist/web-dashboard/server.js +122 -2
- package/dist/web-dashboard/server.js.map +1 -1
- package/dist/web-dashboard/src/types.d.ts +63 -0
- package/dist/web-dashboard/src/types.d.ts.map +1 -1
- package/dist/web-dashboard/task-runner.d.ts +17 -1
- package/dist/web-dashboard/task-runner.d.ts.map +1 -1
- package/dist/web-dashboard/task-runner.js +84 -9
- package/dist/web-dashboard/task-runner.js.map +1 -1
- package/package.json +1 -1
- package/src/web-dashboard/public/assets/index-DeSsNU94.css +1 -0
- package/src/web-dashboard/public/assets/index-Do_O67Kv.js +236 -0
- package/src/web-dashboard/public/assets/index-Do_O67Kv.js.map +1 -0
- package/src/web-dashboard/public/index.html +2 -2
- package/src/web-dashboard/public/assets/index-DycGBWwy.js +0 -236
- package/src/web-dashboard/public/assets/index-DycGBWwy.js.map +0 -1
- package/src/web-dashboard/public/assets/index-aO3aG7ex.css +0 -1
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cost classification — the ONE place that decides which bucket a ledger row
|
|
3
|
+
* belongs to, and what "billed" means for it.
|
|
4
|
+
*
|
|
5
|
+
* WHY IT IS ITS OWN MODULE. Three surfaces judge the same rows — `cost-tracker`
|
|
6
|
+
* (the CLI summary), `web-dashboard/server` (the Cost page + `/api/cost`) and the
|
|
7
|
+
* reconciliation check — and the defect being fixed is precisely that two places
|
|
8
|
+
* priced the same call differently (a hardcoded ledger table vs the provider
|
|
9
|
+
* catalog, disagreeing 25×–100×). So the rule lives here, once, and every surface
|
|
10
|
+
* asks this module instead of deriving its own answer.
|
|
11
|
+
*
|
|
12
|
+
* THE ONE THING TO UNDERSTAND. A ledger row carries two different dollar amounts,
|
|
13
|
+
* and the bug was conflating them:
|
|
14
|
+
*
|
|
15
|
+
* billedUsd money we have EVIDENCE was charged.
|
|
16
|
+
* - exact when the provider reported the call's cost,
|
|
17
|
+
* - an estimate when the account is declared `paid` and a list
|
|
18
|
+
* price is known,
|
|
19
|
+
* - otherwise 0 (free tier, unknown price, pass-through gateway).
|
|
20
|
+
* listValueUsd what the same tokens would cost at the resolved list price —
|
|
21
|
+
* the VALUE a free/subscription tier absorbed, and the figure an
|
|
22
|
+
* undeclared account's rows sit at until the tier is declared.
|
|
23
|
+
*
|
|
24
|
+
* Neither is ever presented as the other, and "unpriced" is a first-class answer
|
|
25
|
+
* rather than a fabricated rate (see `model-pricing.ts` for why: a generic
|
|
26
|
+
* `$0.00010/1K` fallback invented $0.40 of spend on a localhost gateway and
|
|
27
|
+
* under-reported the one provider the user actually pays for).
|
|
28
|
+
*
|
|
29
|
+
* ─── LEGACY ROWS (read before changing classifyEntry) ───────────────────────
|
|
30
|
+
*
|
|
31
|
+
* Rows written before this module existed have no `costSource`: their `costUsd`
|
|
32
|
+
* came from the old hardcoded table. They are NOT trusted for classification and
|
|
33
|
+
* NOT silently relabelled. They are re-derived HERE, at read time, from the fields
|
|
34
|
+
* they do carry (provider, model, tokens, `costReported`) using TODAY's rules —
|
|
35
|
+
* and counted in `recomputedCalls` so a reader can tell re-derived rows from
|
|
36
|
+
* recorded ones. The file is never rewritten by a read: mutating a profile's
|
|
37
|
+
* history to make a dashboard look right is the failure this whole change exists
|
|
38
|
+
* to remove. `scripts/prune-cost-ledger-rows.mjs` is the explicit, dry-run-default
|
|
39
|
+
* way to rewrite them.
|
|
40
|
+
*/
|
|
41
|
+
import { ConfigManager } from '../config/manager.js';
|
|
42
|
+
import { asBillingTier, resolveCallCost, } from './model-pricing.js';
|
|
43
|
+
/** Everything is `unknown`/unset — the honest floor when config cannot be read. */
|
|
44
|
+
export const UNKNOWN_PRICING_CONTEXT = {
|
|
45
|
+
billingTierFor: () => 'unknown',
|
|
46
|
+
configPricingFor: () => undefined,
|
|
47
|
+
};
|
|
48
|
+
/** Build a context from a loaded config (the production path). */
|
|
49
|
+
export function configPricingContext(cm) {
|
|
50
|
+
return {
|
|
51
|
+
billingTierFor(provider) {
|
|
52
|
+
try {
|
|
53
|
+
const p = (cm.getAll().providers || {})[provider];
|
|
54
|
+
return asBillingTier(p?.billingTier);
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return 'unknown';
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
configPricingFor(provider) {
|
|
61
|
+
try {
|
|
62
|
+
const p = (cm.getAll().pricing || {})[provider];
|
|
63
|
+
if (!p)
|
|
64
|
+
return undefined;
|
|
65
|
+
const input = typeof p.inputPer1K === 'number' ? p.inputPer1K : undefined;
|
|
66
|
+
const output = typeof p.outputPer1K === 'number' ? p.outputPer1K : undefined;
|
|
67
|
+
if (input === undefined && output === undefined)
|
|
68
|
+
return undefined;
|
|
69
|
+
// A half-declared override is not a price: filling the missing side with
|
|
70
|
+
// the other one would invent a rate the user never wrote.
|
|
71
|
+
if (input === undefined || output === undefined)
|
|
72
|
+
return undefined;
|
|
73
|
+
return { inputPer1K: input, outputPer1K: output };
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/** A process-wide override for hosts and tests. `null` restores the config path. */
|
|
82
|
+
let overrideContext = null;
|
|
83
|
+
let cachedConfigContext = null;
|
|
84
|
+
export function setPricingContext(ctx) {
|
|
85
|
+
overrideContext = ctx;
|
|
86
|
+
}
|
|
87
|
+
/** Drop the cached config-backed context (tests that switch profiles mid-file). */
|
|
88
|
+
export function resetPricingContextCache() {
|
|
89
|
+
cachedConfigContext = null;
|
|
90
|
+
overrideContext = null;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The context to classify with. Config is read LAZILY and cached, and a failure
|
|
94
|
+
* to read it degrades to `unknown` rather than to an assumption — an accounting
|
|
95
|
+
* layer must never invent a tier.
|
|
96
|
+
*/
|
|
97
|
+
export function getPricingContext() {
|
|
98
|
+
if (overrideContext)
|
|
99
|
+
return overrideContext;
|
|
100
|
+
if (!cachedConfigContext) {
|
|
101
|
+
try {
|
|
102
|
+
cachedConfigContext = configPricingContext(new ConfigManager());
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
cachedConfigContext = UNKNOWN_PRICING_CONTEXT;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return cachedConfigContext;
|
|
109
|
+
}
|
|
110
|
+
const round6 = (usd) => Math.round(usd * 100000) / 100000;
|
|
111
|
+
/**
|
|
112
|
+
* Classify ONE ledger row.
|
|
113
|
+
*
|
|
114
|
+
* A row that already carries `costSource` is taken at its word — it was written
|
|
115
|
+
* by these rules, and re-deriving it with a config that may have changed since
|
|
116
|
+
* would rewrite history. A legacy row (no `costSource`) is re-derived from the
|
|
117
|
+
* fields it has; `costReported` is the one thing a legacy row can be exact about.
|
|
118
|
+
*/
|
|
119
|
+
export function classifyEntry(entry, ctx = getPricingContext()) {
|
|
120
|
+
if (entry.costReported === true) {
|
|
121
|
+
// The provider's own figure, exact — for a legacy row too (the flag was
|
|
122
|
+
// written by the old code and means the same thing).
|
|
123
|
+
return {
|
|
124
|
+
billedUsd: round6(entry.costUsd ?? 0),
|
|
125
|
+
...(typeof entry.listPriceUsd === 'number' ? { listValueUsd: entry.listPriceUsd } : {}),
|
|
126
|
+
costSource: 'reported',
|
|
127
|
+
bucket: 'billed-reported',
|
|
128
|
+
billingTier: entry.billingTier ?? ctx.billingTierFor(entry.provider),
|
|
129
|
+
basis: entry.pricingBasis ?? 'provider-reported cost for this call (exact)',
|
|
130
|
+
recomputed: entry.costSource === undefined,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
if (entry.costSource !== undefined) {
|
|
134
|
+
// Recorded by the current rules: its numbers stand, its bucket is derived.
|
|
135
|
+
const tier = entry.billingTier ?? ctx.billingTierFor(entry.provider);
|
|
136
|
+
return {
|
|
137
|
+
billedUsd: round6(entry.costUsd ?? 0),
|
|
138
|
+
...(typeof entry.listPriceUsd === 'number' ? { listValueUsd: entry.listPriceUsd } : {}),
|
|
139
|
+
costSource: entry.costSource,
|
|
140
|
+
bucket: bucketOf(entry.costSource, tier),
|
|
141
|
+
billingTier: tier,
|
|
142
|
+
basis: entry.pricingBasis ?? 'recorded by the pricing rules',
|
|
143
|
+
recomputed: false,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
// Legacy row: re-derive with today's rules. `reportedCostUsd` is deliberately
|
|
147
|
+
// NOT passed — the stored `costUsd` is the OLD table's number, and feeding it
|
|
148
|
+
// in as though the provider had said it would launder an estimate into an exact
|
|
149
|
+
// figure, which is the single worst mistake this module could make.
|
|
150
|
+
const resolved = resolveCallCost({
|
|
151
|
+
provider: entry.provider,
|
|
152
|
+
model: entry.model,
|
|
153
|
+
inputTokens: entry.inputTokens ?? 0,
|
|
154
|
+
outputTokens: entry.outputTokens ?? 0,
|
|
155
|
+
billingTier: ctx.billingTierFor(entry.provider),
|
|
156
|
+
configPricing: ctx.configPricingFor(entry.provider),
|
|
157
|
+
catalogRow: ctx.catalogRowFor?.(entry.provider, entry.model),
|
|
158
|
+
});
|
|
159
|
+
return {
|
|
160
|
+
billedUsd: resolved.billedUsd,
|
|
161
|
+
...(resolved.listUsd !== undefined ? { listValueUsd: resolved.listUsd } : {}),
|
|
162
|
+
costSource: resolved.costSource,
|
|
163
|
+
bucket: resolved.bucket,
|
|
164
|
+
billingTier: resolved.billingTier,
|
|
165
|
+
basis: resolved.basis,
|
|
166
|
+
recomputed: true,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
/** The bucket for a recorded row — mirrors `model-pricing.bucketFor` for stored data. */
|
|
170
|
+
function bucketOf(source, tier) {
|
|
171
|
+
switch (source) {
|
|
172
|
+
case 'reported':
|
|
173
|
+
return 'billed-reported';
|
|
174
|
+
case 'free':
|
|
175
|
+
return 'not-billed-value';
|
|
176
|
+
case 'passthrough':
|
|
177
|
+
case 'unknown':
|
|
178
|
+
return 'unpriced';
|
|
179
|
+
case 'catalog':
|
|
180
|
+
return tier === 'paid' ? 'billed-listed' : 'unverified-listed';
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
function emptyProviderTotals() {
|
|
184
|
+
return {
|
|
185
|
+
billedUsd: 0,
|
|
186
|
+
unverifiedListedUsd: 0,
|
|
187
|
+
notBilledValueUsd: 0,
|
|
188
|
+
unpricedCalls: 0,
|
|
189
|
+
unverifiedCalls: 0,
|
|
190
|
+
valueCalls: 0,
|
|
191
|
+
requests: 0,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Classify a list of rows and sum them.
|
|
196
|
+
*
|
|
197
|
+
* `excludeTestOrigin` defaults to FALSE, deliberately: this function is also how
|
|
198
|
+
* a TEST measures its own writes (`costSince` reads back rows that are, by
|
|
199
|
+
* definition, test-origin in a test process), so dropping them here would make
|
|
200
|
+
* the ledger read as empty the moment a test runner was involved. The exclusion
|
|
201
|
+
* belongs to the DISPLAY surfaces — the dashboard's cost endpoint and the CLI
|
|
202
|
+
* summary opt in — because that is the claim being made: "this is YOUR usage".
|
|
203
|
+
* `testOriginCalls` is always reported, so a surface can say how many it hid.
|
|
204
|
+
*/
|
|
205
|
+
export function classifyEntries(entries, opts = {}) {
|
|
206
|
+
const ctx = opts.ctx ?? getPricingContext();
|
|
207
|
+
const totals = {
|
|
208
|
+
billedReportedUsd: 0,
|
|
209
|
+
billedReportedCalls: 0,
|
|
210
|
+
billedListedUsd: 0,
|
|
211
|
+
billedListedCalls: 0,
|
|
212
|
+
billedUsd: 0,
|
|
213
|
+
unverifiedListedUsd: 0,
|
|
214
|
+
unverifiedListedCalls: 0,
|
|
215
|
+
notBilledValueUsd: 0,
|
|
216
|
+
notBilledValueCalls: 0,
|
|
217
|
+
unpricedCalls: 0,
|
|
218
|
+
unpricedTokens: 0,
|
|
219
|
+
recomputedCalls: 0,
|
|
220
|
+
testOriginCalls: 0,
|
|
221
|
+
recordedTotalUsd: 0,
|
|
222
|
+
tokens: 0,
|
|
223
|
+
requests: 0,
|
|
224
|
+
byProvider: {},
|
|
225
|
+
byModel: {},
|
|
226
|
+
};
|
|
227
|
+
for (const entry of entries) {
|
|
228
|
+
if (entry.origin === 'test') {
|
|
229
|
+
totals.testOriginCalls += 1;
|
|
230
|
+
if (opts.excludeTestOrigin)
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
const c = classifyEntry(entry, ctx);
|
|
234
|
+
const tokens = entry.totalTokens ?? (entry.inputTokens ?? 0) + (entry.outputTokens ?? 0);
|
|
235
|
+
totals.requests += 1;
|
|
236
|
+
totals.tokens += tokens;
|
|
237
|
+
totals.recordedTotalUsd += entry.costUsd ?? 0;
|
|
238
|
+
if (c.recomputed)
|
|
239
|
+
totals.recomputedCalls += 1;
|
|
240
|
+
if (c.bucket === 'billed-reported') {
|
|
241
|
+
totals.billedReportedUsd += c.billedUsd;
|
|
242
|
+
totals.billedReportedCalls += 1;
|
|
243
|
+
}
|
|
244
|
+
else if (c.bucket === 'billed-listed') {
|
|
245
|
+
totals.billedListedUsd += c.billedUsd;
|
|
246
|
+
totals.billedListedCalls += 1;
|
|
247
|
+
}
|
|
248
|
+
else if (c.bucket === 'unverified-listed') {
|
|
249
|
+
totals.unverifiedListedUsd += c.listValueUsd ?? 0;
|
|
250
|
+
totals.unverifiedListedCalls += 1;
|
|
251
|
+
}
|
|
252
|
+
else if (c.bucket === 'not-billed-value') {
|
|
253
|
+
totals.notBilledValueUsd += c.listValueUsd ?? 0;
|
|
254
|
+
totals.notBilledValueCalls += 1;
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
totals.unpricedCalls += 1;
|
|
258
|
+
totals.unpricedTokens += tokens;
|
|
259
|
+
}
|
|
260
|
+
const provider = entry.provider || 'unknown';
|
|
261
|
+
const p = (totals.byProvider[provider] ??= emptyProviderTotals());
|
|
262
|
+
const m = (totals.byModel[entry.model || 'unknown'] ??= emptyProviderTotals());
|
|
263
|
+
p.requests += 1;
|
|
264
|
+
m.requests += 1;
|
|
265
|
+
if (c.bucket === 'billed-reported' || c.bucket === 'billed-listed') {
|
|
266
|
+
p.billedUsd += c.billedUsd;
|
|
267
|
+
m.billedUsd += c.billedUsd;
|
|
268
|
+
}
|
|
269
|
+
else if (c.bucket === 'unverified-listed') {
|
|
270
|
+
p.unverifiedListedUsd += c.listValueUsd ?? 0;
|
|
271
|
+
p.unverifiedCalls += 1;
|
|
272
|
+
m.unverifiedListedUsd += c.listValueUsd ?? 0;
|
|
273
|
+
m.unverifiedCalls += 1;
|
|
274
|
+
}
|
|
275
|
+
else if (c.bucket === 'not-billed-value') {
|
|
276
|
+
p.notBilledValueUsd += c.listValueUsd ?? 0;
|
|
277
|
+
p.valueCalls += 1;
|
|
278
|
+
m.notBilledValueUsd += c.listValueUsd ?? 0;
|
|
279
|
+
m.valueCalls += 1;
|
|
280
|
+
}
|
|
281
|
+
else {
|
|
282
|
+
p.unpricedCalls += 1;
|
|
283
|
+
m.unpricedCalls += 1;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
totals.billedUsd = round6(totals.billedReportedUsd + totals.billedListedUsd);
|
|
287
|
+
totals.billedReportedUsd = round6(totals.billedReportedUsd);
|
|
288
|
+
totals.billedListedUsd = round6(totals.billedListedUsd);
|
|
289
|
+
totals.unverifiedListedUsd = round6(totals.unverifiedListedUsd);
|
|
290
|
+
totals.notBilledValueUsd = round6(totals.notBilledValueUsd);
|
|
291
|
+
totals.recordedTotalUsd = round6(totals.recordedTotalUsd);
|
|
292
|
+
return totals;
|
|
293
|
+
}
|
|
294
|
+
//# sourceMappingURL=cost-classification.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cost-classification.js","sourceRoot":"","sources":["../../src/learning/cost-classification.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EACL,aAAa,EACb,eAAe,GAIhB,MAAM,oBAAoB,CAAC;AA8B5B,mFAAmF;AACnF,MAAM,CAAC,MAAM,uBAAuB,GAAmB;IACrD,cAAc,EAAE,GAAG,EAAE,CAAC,SAAS;IAC/B,gBAAgB,EAAE,GAAG,EAAE,CAAC,SAAS;CAClC,CAAC;AAEF,kEAAkE;AAClE,MAAM,UAAU,oBAAoB,CAAC,EAAiB;IACpD,OAAO;QACL,cAAc,CAAC,QAAgB;YAC7B,IAAI,CAAC;gBACH,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,QAAQ,CAA0C,CAAC;gBAC3F,OAAO,aAAa,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC;YACvC,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,SAAS,CAAC;YACnB,CAAC;QACH,CAAC;QACD,gBAAgB,CAAC,QAAgB;YAC/B,IAAI,CAAC;gBACH,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,QAAQ,CAEjC,CAAC;gBACd,IAAI,CAAC,CAAC;oBAAE,OAAO,SAAS,CAAC;gBACzB,MAAM,KAAK,GAAG,OAAO,CAAC,CAAC,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC;gBAC1E,MAAM,MAAM,GAAG,OAAO,CAAC,CAAC,W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AS,GAAG,MAAM,CAAC,MAAM,CAAC,iBAAiB,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC;IAC7E,MAAM,CAAC,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;IAC5D,MAAM,CAAC,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;IACxD,MAAM,CAAC,mBAAmB,GAAG,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC;IAChE,MAAM,CAAC,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;IAC5D,MAAM,CAAC,gBAAgB,GAAG,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;IAC1D,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cost-ledger maintenance — the EXPLICIT, dry-run-default way to repair the rows
|
|
3
|
+
* already on disk. Nothing here runs on a read: the ledger is repaired only when
|
|
4
|
+
* an operator asks for it, and every figure it changes is reported before and
|
|
5
|
+
* after.
|
|
6
|
+
*
|
|
7
|
+
* WHY IT EXISTS. Two classes of row in a real profile are not what they look like,
|
|
8
|
+
* and neither can be fixed by a read:
|
|
9
|
+
*
|
|
10
|
+
* 1. LEGACY PRICES. Rows written before `costSource` existed carry a `costUsd`
|
|
11
|
+
* computed from the retired hardcoded table (`cost-tracker.ts`'s five-entry
|
|
12
|
+
* `DEFAULT_PRICING` plus a `$0.00010/1K` generic fallback). Read-side
|
|
13
|
+
* classification already re-derives them for DISPLAY (`cost-classification.ts`
|
|
14
|
+
* counts them in `recomputedCalls`), and deliberately never rewrites the file
|
|
15
|
+
* — but `recordedTotalUsd` ("the ledger total as recorded") keeps showing the
|
|
16
|
+
* old number, and a reprice is what turns the file itself honest.
|
|
17
|
+
* 2. TEST-ORIGIN ROWS. A row a test run wrote into a real profile. Rows written
|
|
18
|
+
* since `origin` was added say so (`origin: 'test'`); rows from before have no
|
|
19
|
+
* field at all, and the only sound evidence left in them is the model id — a
|
|
20
|
+
* fixture id (`wire-stub-model`: MEASURED 747 rows in a real
|
|
21
|
+
* `~/.nuvira/memory/cost-tracker.json`) could not have come from a real call.
|
|
22
|
+
*
|
|
23
|
+
* ─── WHAT IT REFUSES TO DO (read before changing either rule) ───────────────
|
|
24
|
+
*
|
|
25
|
+
* - It does NOT re-derive a row that already carries `costSource`. That row was
|
|
26
|
+
* written by today's rules under the config in force at the time; re-pricing it
|
|
27
|
+
* with a config that has changed since would rewrite history to match the
|
|
28
|
+
* present — the exact dishonesty this whole change removes.
|
|
29
|
+
* - It does NOT pass a legacy row's stored `costUsd` back in as though the
|
|
30
|
+
* provider had reported it. The stored number is the old estimate; feeding it
|
|
31
|
+
* into `resolveCallCost` as `reportedCostUsd` would LAUNDER an estimate into an
|
|
32
|
+
* exact-looking figure. Only a row already flagged `costReported: true` keeps
|
|
33
|
+
* its number verbatim, because that flag was written by the old code and means
|
|
34
|
+
* the same thing.
|
|
35
|
+
* - It does NOT guess `origin`. A legacy row gets no origin field: we do not know
|
|
36
|
+
* which process wrote it, and stamping `live` would make it unprunable forever.
|
|
37
|
+
* - It NEVER writes without `apply`, and a write always leaves a `.bak` beside the
|
|
38
|
+
* file (the ledger is the user's billing history; a reprice is reversible).
|
|
39
|
+
*/
|
|
40
|
+
import type { CostEntry } from './cost-tracker.js';
|
|
41
|
+
import { type PricingContext } from './cost-classification.js';
|
|
42
|
+
/** One grouped removal, so the report says WHAT is being dropped, not just how many. */
|
|
43
|
+
export interface RemovedRows {
|
|
44
|
+
provider: string;
|
|
45
|
+
model: string;
|
|
46
|
+
count: number;
|
|
47
|
+
/** True when the id itself is the evidence (a fixture id), not an `origin` tag. */
|
|
48
|
+
fixtureId: boolean;
|
|
49
|
+
}
|
|
50
|
+
export interface LedgerMaintenanceReport {
|
|
51
|
+
file: string;
|
|
52
|
+
applied: boolean;
|
|
53
|
+
backupPath?: string;
|
|
54
|
+
rows: {
|
|
55
|
+
total: number;
|
|
56
|
+
/** Legacy rows re-derived by today's rules (they gained `costSource`). */
|
|
57
|
+
repriced: number;
|
|
58
|
+
/** Rows already written by these rules — left exactly as they were. */
|
|
59
|
+
alreadyClassified: number;
|
|
60
|
+
/** Rows flagged `origin: 'test'`. */
|
|
61
|
+
testOriginRemoved: number;
|
|
62
|
+
/** Rows whose model id could only be a test fixture (no `origin` field). */
|
|
63
|
+
fixtureRemoved: number;
|
|
64
|
+
kept: number;
|
|
65
|
+
};
|
|
66
|
+
/** The ledger's own recorded sum before and after — the number a reader sees. */
|
|
67
|
+
before: {
|
|
68
|
+
recordedUsd: number;
|
|
69
|
+
tokens: number;
|
|
70
|
+
unpricedCalls: number;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Re-priced totals, classified: `recordedUsd` is the new sum of the rows'
|
|
74
|
+
* `costUsd` (the evidence-backed figure), and the rest is the honest split.
|
|
75
|
+
*/
|
|
76
|
+
after: {
|
|
77
|
+
recordedUsd: number;
|
|
78
|
+
tokens: number;
|
|
79
|
+
billedUsd: number;
|
|
80
|
+
billedReportedUsd: number;
|
|
81
|
+
billedListedUsd: number;
|
|
82
|
+
unverifiedListedUsd: number;
|
|
83
|
+
notBilledValueUsd: number;
|
|
84
|
+
unpricedCalls: number;
|
|
85
|
+
};
|
|
86
|
+
removed: RemovedRows[];
|
|
87
|
+
/** Plain-language notes: what changed and what still needs the operator. */
|
|
88
|
+
notes: string[];
|
|
89
|
+
}
|
|
90
|
+
/** True when the row is test-origin by evidence we can actually read. */
|
|
91
|
+
export declare function testRowVerdict(entry: {
|
|
92
|
+
origin?: string;
|
|
93
|
+
model?: string;
|
|
94
|
+
}): 'test-origin' | 'fixture-id' | null;
|
|
95
|
+
/**
|
|
96
|
+
* Re-price a set of ledger rows and (optionally) drop the test rows among them.
|
|
97
|
+
* Pure: takes rows, returns rows — the file is written by `maintainCostLedger`.
|
|
98
|
+
*/
|
|
99
|
+
export declare function repriceLedgerEntries(entries: readonly CostEntry[], opts?: {
|
|
100
|
+
ctx?: PricingContext;
|
|
101
|
+
pruneTestRows?: boolean;
|
|
102
|
+
}): {
|
|
103
|
+
entries: CostEntry[];
|
|
104
|
+
report: Omit<LedgerMaintenanceReport, 'file' | 'applied' | 'backupPath'>;
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* The whole pass against a FILE. `apply: false` (the default) reads and reports
|
|
108
|
+
* only — the dry run is the default because the ledger is billing history.
|
|
109
|
+
*
|
|
110
|
+
* On `apply` the previous file is copied to `<file>.bak` first (a fixed name, so
|
|
111
|
+
* the backup is the state immediately before THIS run and cannot itself grow a
|
|
112
|
+
* chain), and the rewrite goes through a temp-free single write.
|
|
113
|
+
*/
|
|
114
|
+
export declare function maintainCostLedger(opts?: {
|
|
115
|
+
file?: string;
|
|
116
|
+
apply?: boolean;
|
|
117
|
+
pruneTestRows?: boolean;
|
|
118
|
+
ctx?: PricingContext;
|
|
119
|
+
}): LedgerMaintenanceReport;
|
|
120
|
+
/** The report as text — shared by the CLI and the scripts wrapper. */
|
|
121
|
+
export declare function formatMaintenanceReport(rep: LedgerMaintenanceReport): string;
|
|
122
|
+
//# sourceMappingURL=cost-ledger-maintenance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cost-ledger-maintenance.d.ts","sourceRoot":"","sources":["../../src/learning/cost-ledger-maintenance.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAKH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,EAIL,KAAK,cAAc,EACpB,MAAM,0BAA0B,CAAC;AAWlC,wFAAwF;AACxF,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,mFAAmF;IACnF,SA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