@xiangyixie/dsh-superagent 0.12.1 → 0.14.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/CHANGELOG.md +171 -8
- package/LICENSE +21 -21
- package/README.md +522 -40
- package/bin/doctor.js +1 -1
- package/cordis.patch.yml +9 -9
- package/lib/audit.js +8 -1
- package/lib/browser.js +795 -0
- package/lib/console.js +763 -0
- package/lib/cost.js +71 -11
- package/lib/cron.js +387 -0
- package/lib/desktop.js +507 -0
- package/lib/doctor.js +1 -0
- package/lib/goal.js +649 -0
- package/lib/guard.js +15 -0
- package/lib/index.js +1296 -42
- package/lib/ledger.js +26 -12
- package/lib/orchestrator.js +1765 -136
- package/lib/report.js +59 -29
- package/lib/runtime-control.js +1151 -0
- package/lib/schedule.js +1030 -0
- package/lib/store.js +6 -2
- package/lib/user-memory.js +587 -0
- package/lib/watch.js +25 -17
- package/lib/workbench.js +7 -7
- package/lib/workspace.js +88 -27
- package/package.json +101 -92
- package/public/console.html +1618 -0
package/lib/ledger.js
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import fsp from 'node:fs/promises'
|
|
17
17
|
import path from 'node:path'
|
|
18
|
+
import { addCurrencyMicros, currencyTotals } from './cost.js'
|
|
18
19
|
import { TERMINAL_STATUSES } from './store.js'
|
|
19
20
|
|
|
20
21
|
const LEDGER_VERSION = 1
|
|
@@ -37,7 +38,7 @@ function fingerprintOf(run) {
|
|
|
37
38
|
run.status ?? '',
|
|
38
39
|
run.finishedAt ?? '',
|
|
39
40
|
run.usage?.modelCalls ?? 0,
|
|
40
|
-
run.cost?.totalMicros ?? '',
|
|
41
|
+
run.cost?.totalMicros ?? JSON.stringify(run.cost?.byCurrency ?? ''),
|
|
41
42
|
].join('|')
|
|
42
43
|
}
|
|
43
44
|
|
|
@@ -128,9 +129,14 @@ export function createLedger(root, options = {}) {
|
|
|
128
129
|
calls: run.usage.modelCalls ?? 0,
|
|
129
130
|
tokens: run.usage.totalTokens
|
|
130
131
|
?? (run.usage.inputTokens ?? 0) + (run.usage.cacheReadTokens ?? 0) + (run.usage.outputTokens ?? 0),
|
|
131
|
-
currency: cost.currency ?? 'USD',
|
|
132
|
-
totalMicros: Number.isFinite(cost.totalMicros)
|
|
133
|
-
|
|
132
|
+
currency: cost.currency ?? (cost.mixedCurrency ? null : 'USD'),
|
|
133
|
+
totalMicros: Number.isFinite(cost.totalMicros)
|
|
134
|
+
? cost.totalMicros
|
|
135
|
+
: (Number.isFinite(cost.total) ? Math.round(cost.total * 1e6) : null),
|
|
136
|
+
total: Number.isFinite(cost.total) ? cost.total : (Number.isFinite(cost.totalMicros) ? cost.totalMicros / 1e6 : null),
|
|
137
|
+
// A mixed-currency run has no single number; the per-currency amounts
|
|
138
|
+
// travel with the line so a later summary can still add them correctly.
|
|
139
|
+
byCurrency: cost.byCurrency && typeof cost.byCurrency === 'object' ? { ...cost.byCurrency } : {},
|
|
134
140
|
complete: cost.complete === true,
|
|
135
141
|
unpriced: Array.isArray(cost.unpriced) ? [...cost.unpriced] : [],
|
|
136
142
|
models: cost.records.map(model => ({
|
|
@@ -208,24 +214,30 @@ export function createLedger(root, options = {}) {
|
|
|
208
214
|
async function summarize(range = {}) {
|
|
209
215
|
const entries = await read(range)
|
|
210
216
|
const byModel = {}
|
|
217
|
+
const byCurrency = {}
|
|
211
218
|
let calls = 0
|
|
212
219
|
let tokens = 0
|
|
213
|
-
let totalMicros = 0
|
|
214
220
|
let priced = 0
|
|
215
221
|
let unpricedRuns = 0
|
|
216
|
-
const currencies = new Set()
|
|
217
222
|
let start = null
|
|
218
223
|
let end = null
|
|
219
224
|
for (const entry of entries) {
|
|
220
225
|
const totals = lineTotals(entry)
|
|
221
226
|
calls += Number(entry.calls) || totals.calls
|
|
222
227
|
tokens += Number(entry.tokens) || totals.tokens
|
|
223
|
-
|
|
228
|
+
// New lines carry the per-currency split. A line written before that
|
|
229
|
+
// field existed has one currency and one total, which is still exact.
|
|
230
|
+
const lineByCurrency = entry.byCurrency && typeof entry.byCurrency === 'object'
|
|
231
|
+
&& Object.keys(entry.byCurrency).length > 0
|
|
232
|
+
? entry.byCurrency
|
|
233
|
+
: (entry.currency ? { [entry.currency]: Number(entry.totalMicros) || 0 } : {})
|
|
234
|
+
for (const [code, micros] of Object.entries(lineByCurrency)) {
|
|
235
|
+
addCurrencyMicros(byCurrency, code, Number(micros) || 0)
|
|
236
|
+
}
|
|
224
237
|
const models = Array.isArray(entry.models) ? entry.models : []
|
|
225
238
|
const hasPriced = models.some(model => Number.isFinite(model.amountMicros))
|
|
226
239
|
if (hasPriced) priced += 1
|
|
227
240
|
if (entry.complete !== true) unpricedRuns += 1
|
|
228
|
-
if (entry.currency) currencies.add(entry.currency)
|
|
229
241
|
const at = timeOf(entry.at)
|
|
230
242
|
if (at !== null) {
|
|
231
243
|
start = start === null ? at : Math.min(start, at)
|
|
@@ -250,17 +262,19 @@ export function createLedger(root, options = {}) {
|
|
|
250
262
|
}
|
|
251
263
|
}
|
|
252
264
|
}
|
|
265
|
+
const totals = currencyTotals(byCurrency)
|
|
253
266
|
return {
|
|
254
267
|
runs: entries.length,
|
|
255
268
|
priced,
|
|
256
269
|
unpricedRuns,
|
|
257
270
|
calls,
|
|
258
271
|
tokens,
|
|
259
|
-
totalMicros,
|
|
260
|
-
total:
|
|
272
|
+
totalMicros: totals.totalMicros,
|
|
273
|
+
total: totals.total,
|
|
261
274
|
byModel,
|
|
262
|
-
|
|
263
|
-
|
|
275
|
+
byCurrency,
|
|
276
|
+
currency: totals.currency,
|
|
277
|
+
mixedCurrency: totals.mixedCurrency,
|
|
264
278
|
start,
|
|
265
279
|
end,
|
|
266
280
|
}
|