aegiscode 6.7.2 → 6.7.3
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/package.json +1 -1
- package/vendor/desktop/renderer/usage.js +163 -7
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aegiscode",
|
|
3
3
|
"productName": "AEGIS Code",
|
|
4
|
-
"version": "6.7.
|
|
4
|
+
"version": "6.7.3",
|
|
5
5
|
"description": "aegiscode — the command-line version of AEGIS Desktop. The shared tool surface in your shell, over the same thin transport and tool registry as the MCP plugin and the desktop app. Ships transport + UI only; no brain.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "AEGIS Code",
|
|
@@ -66,6 +66,56 @@ function usageTokens(usage) {
|
|
|
66
66
|
return (input || 0) + (output || 0);
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
/**
|
|
70
|
+
* Rough token count for text the wire never measured — a direct port of the
|
|
71
|
+
* CLI's own estimator (`aegiscodex-dev/src/tokens.js estimateTokens`), and the
|
|
72
|
+
* reason its session total is MONOTONIC.
|
|
73
|
+
*
|
|
74
|
+
* This is the whole difference being fixed. The CLI's `appendHistory`
|
|
75
|
+
* (aegiscodex-dev/src/history.js) writes a `tokens` object for EVERY finished
|
|
76
|
+
* exchange: `{input, output, cacheRead, cacheWrite, real: true}` when the wire
|
|
77
|
+
* reported usage, and `{input: estimateTokens(prompt), output:
|
|
78
|
+
* estimateTokens(reply), real: false}` when it did not. `real` is a FLAG, not a
|
|
79
|
+
* gate — `aggregateSessionUsage` adds `t.input || 0` for every row regardless,
|
|
80
|
+
* so a turn without usage still moves the total and only marks it as partly
|
|
81
|
+
* estimated.
|
|
82
|
+
*
|
|
83
|
+
* The desktop rolled only reported usage and dropped everything else, so its
|
|
84
|
+
* total was flat across any turn the pool did not report on — the meter looked
|
|
85
|
+
* dead while the conversation was being billed. ~4 characters per token, the
|
|
86
|
+
* CLI's heuristic, kept identical so the two surfaces estimate the same turn
|
|
87
|
+
* the same way. Empty text is 0, never the `Math.max(1, …)` floor.
|
|
88
|
+
*/
|
|
89
|
+
function estimateTokens(text) {
|
|
90
|
+
if (!text) return 0;
|
|
91
|
+
return Math.max(1, Math.ceil([...String(text)].length / 4));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* The bucket shape an exchange gets when the wire reported no usage: the CLI's
|
|
96
|
+
* `{input: estimateTokens(prompt), output: estimateTokens(reply)}`.
|
|
97
|
+
*
|
|
98
|
+
* `null` when there is no text at all to estimate from, so a dispatch that
|
|
99
|
+
* genuinely reported nothing (no usage, no prompt, no reply) still lands in
|
|
100
|
+
* `unknown` instead of being handed a fabricated zero.
|
|
101
|
+
*
|
|
102
|
+
* @param {string} [prompt]
|
|
103
|
+
* @param {string} [reply]
|
|
104
|
+
* @returns {{input: number, output: number, cacheRead: number, cacheWrite: number}|null}
|
|
105
|
+
*/
|
|
106
|
+
function estimatedBuckets(prompt, reply) {
|
|
107
|
+
const hasPrompt = typeof prompt === 'string' && prompt.length > 0;
|
|
108
|
+
const hasReply = typeof reply === 'string' && reply.length > 0;
|
|
109
|
+
if (!hasPrompt && !hasReply) return null;
|
|
110
|
+
return {
|
|
111
|
+
input: estimateTokens(prompt),
|
|
112
|
+
output: estimateTokens(reply),
|
|
113
|
+
cacheRead: 0,
|
|
114
|
+
cacheWrite: 0,
|
|
115
|
+
real: false,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
69
119
|
// Per-million-token USD rates. Cache-read/write matter for long sessions.
|
|
70
120
|
//
|
|
71
121
|
// These are the PROVIDER's rates, for the fallback path where a turn has no
|
|
@@ -239,6 +289,12 @@ function emptyRoll() {
|
|
|
239
289
|
cacheWrite: 0,
|
|
240
290
|
/** Dispatches that reported no usage at all — the honest gap in `tokens`. */
|
|
241
291
|
unknown: 0,
|
|
292
|
+
/**
|
|
293
|
+
* Exchanges folded from TEXT rather than reported usage, on the CLI's
|
|
294
|
+
* `real: false` rule. They are counted in `tokens` — that is the point —
|
|
295
|
+
* and named here so an estimated figure is never read as a measured one.
|
|
296
|
+
*/
|
|
297
|
+
estimated: 0,
|
|
242
298
|
/** Settled charges (server-settled `costUsd`), rolled. */
|
|
243
299
|
cost: 0,
|
|
244
300
|
/** Locally priced turns, rolled. Never mixed into `cost`. */
|
|
@@ -253,11 +309,14 @@ function emptyRoll() {
|
|
|
253
309
|
*
|
|
254
310
|
* @param {object} [roll] the roll so far (emptyRoll() when omitted)
|
|
255
311
|
* @param {object} [usage] the response's `usage` object
|
|
256
|
-
* @param {{model?: string, costUsd?: number, calls?: number, turns?: number
|
|
312
|
+
* @param {{model?: string, costUsd?: number, calls?: number, turns?: number,
|
|
313
|
+
* prompt?: string, reply?: string, estimated?: boolean}} [opts]
|
|
257
314
|
* `calls` defaults to 1; a pooled turn may report how many provider
|
|
258
315
|
* calls it actually made. `turns: 0` folds a dispatch that is not a
|
|
259
316
|
* turn of its own — the discovery-lane card, which bills like any other
|
|
260
|
-
* call but is not something the user asked for.
|
|
317
|
+
* call but is not something the user asked for. `prompt`/`reply` are the
|
|
318
|
+
* turn's text, used ONLY when the wire reported no usage, so the turn is
|
|
319
|
+
* estimated rather than dropped (the CLI's `appendHistory` rule).
|
|
261
320
|
* @returns {object} the new roll
|
|
262
321
|
*/
|
|
263
322
|
function rollTurn(roll, usage, opts = {}) {
|
|
@@ -265,8 +324,31 @@ function rollTurn(roll, usage, opts = {}) {
|
|
|
265
324
|
next.turns += opts.turns === undefined ? 1 : Number(opts.turns) || 0;
|
|
266
325
|
next.calls += opts.calls === undefined ? 1 : Number(opts.calls) || 0;
|
|
267
326
|
const turn = turnAccounting(usage, opts.model, { costUsd: opts.costUsd });
|
|
327
|
+
// A row folded from text rather than from the wire: either this turn's own
|
|
328
|
+
// fallback below, or a stored ledger row carrying `real: false` — the shape
|
|
329
|
+
// the CLI's `appendHistory` writes for an exchange the provider did not
|
|
330
|
+
// report on.
|
|
331
|
+
const estimated = opts.estimated === true || (usage && usage.real === false);
|
|
268
332
|
if (turn.tokens == null) {
|
|
269
|
-
|
|
333
|
+
// No reported usage. The CLI does not let such a turn vanish from the
|
|
334
|
+
// total: `appendHistory` estimates it from the text and marks it
|
|
335
|
+
// `real: false` (aegiscodex-dev/src/history.js), and
|
|
336
|
+
// `aggregateSessionUsage` then adds it like any other row. Folding the same
|
|
337
|
+
// estimate here is what makes the live roll and the rebuilt roll the same
|
|
338
|
+
// number, and what stops the total standing still on exactly the turns the
|
|
339
|
+
// pool declined to report on — the symptom this fallback exists to remove.
|
|
340
|
+
const est = estimatedBuckets(opts.prompt, opts.reply);
|
|
341
|
+
if (!est) {
|
|
342
|
+
// Nothing reported AND no text to estimate from. The single case that
|
|
343
|
+
// stays uncounted: `unknown` names the gap, where a fabricated zero would
|
|
344
|
+
// read as a measurement.
|
|
345
|
+
next.unknown += 1;
|
|
346
|
+
return next;
|
|
347
|
+
}
|
|
348
|
+
next.tokens += est.input + est.output;
|
|
349
|
+
next.input += est.input;
|
|
350
|
+
next.output += est.output;
|
|
351
|
+
next.estimated += 1;
|
|
270
352
|
return next;
|
|
271
353
|
}
|
|
272
354
|
const b = usageBuckets(usage);
|
|
@@ -275,6 +357,14 @@ function rollTurn(roll, usage, opts = {}) {
|
|
|
275
357
|
next.output += b.output;
|
|
276
358
|
next.cacheRead += b.cacheRead;
|
|
277
359
|
next.cacheWrite += b.cacheWrite;
|
|
360
|
+
if (estimated) {
|
|
361
|
+
// Money stays out of an estimated exchange, deliberately and in both
|
|
362
|
+
// directions: the CLI writes no `costUsd` for one, so pricing it here would
|
|
363
|
+
// make the live roll drift from the rebuilt one — and pricing tokens that
|
|
364
|
+
// were themselves guessed would stack one guess on another.
|
|
365
|
+
next.estimated += 1;
|
|
366
|
+
return next;
|
|
367
|
+
}
|
|
278
368
|
if (turn.real) next.cost += turn.cost;
|
|
279
369
|
else if (turn.cost != null) next.estimate += turn.cost;
|
|
280
370
|
return next;
|
|
@@ -307,6 +397,55 @@ function rollMessages(messages) {
|
|
|
307
397
|
return roll;
|
|
308
398
|
}
|
|
309
399
|
|
|
400
|
+
/**
|
|
401
|
+
* The ledger row one finished dispatch must carry into the shared session
|
|
402
|
+
* store, so the rolling total can be REBUILT when the thread is reopened —
|
|
403
|
+
* the desktop's counterpart of the CLI's `appendHistory`
|
|
404
|
+
* (aegiscodex-dev/src/history.js:36).
|
|
405
|
+
*
|
|
406
|
+
* One authority for the row, on purpose. The CLI writes a `tokens` object for
|
|
407
|
+
* EVERY exchange and skips none:
|
|
408
|
+
*
|
|
409
|
+
* tokens: usage
|
|
410
|
+
* ? { input, output, cacheRead, cacheWrite, real: true }
|
|
411
|
+
* : { input: estimateTokens(prompt), output: estimateTokens(reply), real: false }
|
|
412
|
+
*
|
|
413
|
+
* …and `aggregateSessionUsage` then sums `t.input || 0` over every entry with
|
|
414
|
+
* `real` as a FLAG, not a gate. Mirroring that shape here is what makes the
|
|
415
|
+
* live roll and the rebuilt roll the same number: `rollTurn` is handed this
|
|
416
|
+
* exact object on reopen, so an estimated exchange adds the same buckets it
|
|
417
|
+
* added live and is counted under `estimated` in both.
|
|
418
|
+
*
|
|
419
|
+
* Returns `null` when there is neither reported usage nor text to estimate
|
|
420
|
+
* from — the one case that must stay unrecorded, because a fabricated
|
|
421
|
+
* `{input: 0, output: 0}` row would read as a measured zero forever after.
|
|
422
|
+
*
|
|
423
|
+
* @param {object} [usage] the response's `usage` object
|
|
424
|
+
* @param {object} [turn] its accounting (turnAccounting), when already done
|
|
425
|
+
* @param {{model?: string, costUsd?: number, calls?: number, prompt?: string,
|
|
426
|
+
* reply?: string}} [opts]
|
|
427
|
+
* @returns {object|null} the row's ledger fields
|
|
428
|
+
*/
|
|
429
|
+
function ledgerRow(usage, turn, opts = {}) {
|
|
430
|
+
const t = turn || turnAccounting(usage, opts.model, { costUsd: opts.costUsd });
|
|
431
|
+
const calls = Number.isFinite(opts.calls) && opts.calls > 0 ? opts.calls : undefined;
|
|
432
|
+
if (t.tokens != null) {
|
|
433
|
+
const row = { tokens: usageBuckets(usage) };
|
|
434
|
+
// Only a SETTLED charge is persisted. The CLI writes `costUsd` for a real
|
|
435
|
+
// charge only, and the rebuild prices an unpriced row from the same rate
|
|
436
|
+
// table this window used — persisting a local guess would let a stale
|
|
437
|
+
// table outlive the change that wrote it.
|
|
438
|
+
if (t.real && t.cost != null) row.costUsd = t.cost;
|
|
439
|
+
if (calls !== undefined) row.calls = calls;
|
|
440
|
+
return row;
|
|
441
|
+
}
|
|
442
|
+
const est = estimatedBuckets(opts.prompt, opts.reply);
|
|
443
|
+
if (!est) return null;
|
|
444
|
+
const row = { tokens: est };
|
|
445
|
+
if (calls !== undefined) row.calls = calls;
|
|
446
|
+
return row;
|
|
447
|
+
}
|
|
448
|
+
|
|
310
449
|
/**
|
|
311
450
|
* The CLI's rendering of a session tally — `cli/src/format.js fmtTokens`, which
|
|
312
451
|
* is the one `tokenSummary` actually imports (`cli/src/app.js:50`). NOT the
|
|
@@ -343,10 +482,19 @@ function fmtRoll(roll) {
|
|
|
343
482
|
// are kept, because a line that is only *sometimes* shaped like the CLI's is a
|
|
344
483
|
// lookalike rather than the same quantity. The call count is also the number
|
|
345
484
|
// that reveals a fan-out, which is why it is not hidden at 1.
|
|
346
|
-
const bits = [
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
485
|
+
const bits = [];
|
|
486
|
+
// The token half only when something was actually counted. `rollTurn` counts
|
|
487
|
+
// turns and calls BEFORE it looks at the token count, so a dispatch that
|
|
488
|
+
// reported nothing still reaches here — and printing its empty tally would
|
|
489
|
+
// put `0 tok (0 in / 0 out)` on the topbar, a figure the meter never took,
|
|
490
|
+
// which reads as a counter that does not move. The turn count is still
|
|
491
|
+
// stated, because that much is true.
|
|
492
|
+
if (r.tokens > 0) {
|
|
493
|
+
bits.push(
|
|
494
|
+
`${fmtTokens(r.tokens)} tok (${fmtTokens(r.input)} in / ${fmtTokens(r.output)} out)`
|
|
495
|
+
);
|
|
496
|
+
}
|
|
497
|
+
bits.push(`${r.calls} call${r.calls === 1 ? '' : 's'}`);
|
|
350
498
|
// Money is where this line departs from `tokenSummary`, deliberately: that
|
|
351
499
|
// one sums a single `session.cost` in EUR via fmtEur, while this surface keeps
|
|
352
500
|
// a settled charge and a local estimate apart so a `~`-estimate can never be
|
|
@@ -363,6 +511,11 @@ function fmtRoll(roll) {
|
|
|
363
511
|
// the count appears only when something went unreported, and it never changes
|
|
364
512
|
// a number — it only says the number is not the whole story.
|
|
365
513
|
if (r.unknown) bits.push(`${r.unknown} unrpt`);
|
|
514
|
+
// The other half of the same honesty: a total that includes estimated
|
|
515
|
+
// exchanges says so, because the CLI marks the same rows `real: false` and a
|
|
516
|
+
// reader is entitled to know which figure they are looking at. It changes no
|
|
517
|
+
// number — it says the number is partly inferred.
|
|
518
|
+
if (r.estimated) bits.push(`${r.estimated} est`);
|
|
366
519
|
return bits.join(' · ');
|
|
367
520
|
}
|
|
368
521
|
|
|
@@ -387,9 +540,12 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
387
540
|
usageBuckets,
|
|
388
541
|
usageCost,
|
|
389
542
|
turnAccounting,
|
|
543
|
+
estimateTokens,
|
|
544
|
+
estimatedBuckets,
|
|
390
545
|
emptyRoll,
|
|
391
546
|
rollTurn,
|
|
392
547
|
rollMessages,
|
|
548
|
+
ledgerRow,
|
|
393
549
|
fmtTokens,
|
|
394
550
|
fmtRoll,
|
|
395
551
|
fmtCost,
|